--- title: Recreating Steffl's Flatfields keywords: fastai sidebar: home_sidebar summary: "Based on his thesis appendix" description: "Based on his thesis appendix" nb_path: "notebooks/06_calib.steffl.ipynb" ---
missing = [] there = [] for id in obsids: try: data = UVPDS(id, skip_download=True) except FileNotFoundError: print(id, "not there.") missing.append(id) else: print("Got", id) there.append(id)
cat = CatalogFilter(steffl_spica_dates[2])
pids = list(cat.get_euv_date().query("OBSERVATION_TYPE=='CALIB'").index)
pids
cat.set_next_day()
pids.extend(list(cat.get_euv_date().query("OBSERVATION_TYPE=='CALIB'").index))
pids
kwargs = {"x": "nx", "y": "ny", "cmap": "viridis", "clim": (0, 50)}
class Row2Row:
def __init__(self, pid):
self.pid = pid
self.data = UVPDS(pid).xarray.astype("int16")
@property
def plot_set(self):
return self.data.hvplot(
x="spectral", y="spatial", cmap="viridis", title=self.pid
)
@property
def integrated(self):
return self.data.sum(dim="samples")
@property
def plot_integrated(self):
return self.integrated.hvplot(
x="spectral", y="spatial", cmap="viridis", title=self.pid
)
@property
def averaged(self):
return self.integrated.sel(spatial=slice(3, 61)).mean(dim="spatial")
@property
def plot_averaged(self):
return self.averaged.hvplot(x="spectral", title=self.pid)
@property
def column_std(self):
return self.integrated.sel(spatial=slice(2, 60)).std(dim="spatial")
@property
def plot_column_std(self):
return self.column_std.hvplot(x="spectral", title=f"{self.pid}, Column STD")
@property
def ff(self):
data = self.averaged / self.integrated
data = data.where(np.isfinite(data), other=np.nan)
data.loc[:, 61:] = 1
data.loc[:, :3] = 1
return data
@property
def plot_ff(self):
return self.ff.hvplot(
x="spectral", y="spatial", cmap="viridis", title=self.pid, clim=(None, 4)
)
pids
r2r = Row2Row(pids[0])
r2r.plot_ff
r2r.plot_integrated
r2r.plot_column_std
r2r.integrated.hvplot(x="spatial")
r2r.ff
def create_detector_stack(
data, # numpy 3D array to embed to xarray
name, # name of data
third_dim, # name of third dimension ("scan", "along", "across")
orig, # xarray to copy coords from
):
"""Function to create a 2D detector array with variable 3rd dimensions.
It uses an `orig` array to copy the coordinates from.
"""
return xr.DataArray(
data,
dims=["spectral", "spatial"] + [third_dim],
coords={
"spectral": orig.spectral,
"spatial": orig.spatial,
third_dim: range(data.shape[-1]),
},
name=name,
)
c2c = Col2Col(pids)
c2c.calculate_simple_correction()
c2c.plot_all_Fm()
c2c.plot_simple_correction()
c2c.plot_r2r_flats()
c2c.r2r_flat_average_plot()
c2c.simple_both_plot()
c2c.i=100
c2c.m=0
c2c.plot_triplet()
c2c.plot_triplet(corrected=True)
p1 = (
c2c.arr.where(c2c.arr > 0, np.nan)
.isel(across_slit=0, drop=True)
.hvplot.image(x="spectral", cmap="viridis", logz=True, label="Original")
)
dataset = c2c.arr.isel(across_slit=0, drop=True).to_dataset(name=c2c.arr.name)
dataset
dims = [c for c in dataset.coords if dataset[c].shape != ()][::-1]
dims
index_dims = [d for d in dims if d in dataset.indexes]
index_dims
c2c.arr.isel(across_slit=0, drop=True).indexes
p1
p2 = (
c2c.corrected_arr.where(c2c.corrected_arr > 0, np.nan)
.isel(across_slit=0, drop=True)
.hvplot.image(x="spectral", cmap="viridis", logz=True, label="Corrected")
)
(p1+p2).cols(1)
c2c.simple_both.isel(spectral=slice(15, 998), spatial=slice(3,61)).mean().data
iarr = c2c.arr.interactive()
from panel import widgets
ival = widgets.IntSlider(start=0, end=1024)
mval = widgets.IntSlider()
iarr.isel(spectral=ival, drop=True).hvplot().layout()
c2c.calculate_simple_correction()
c2c.simple_correction
c2c.i = 200
c2c.m = 0
c2c.column_set_mean() / c2c.column_set()[0]
c2c.column_set()[0]
c2c.i = 200
c2c.m = 3
c2c.plot_averaged_triplet()
c2c.plot_triplet(corrected=False, i=300)
c2c.plot_simple_correction()
c2c.simple_correction.shape
c2c.plot_Fm(0)
c2c.plot_triplet()
c2c.column_set_mean()
c2c.plot()
archive_df.loc["EUV2001_093_08_35_28"]
p = obsdir / "index_repaired.tab"
df = pd.read_csv(p, quotechar='"', skipinitialspace=True)
from planetarypy.pds.indexes import find_mixed_type_cols
find_mixed_type_cols(df, fix=False)
df.columns
index.columns
index[index.filename.str.startswith("EUV")].iloc[0]
obs.head()
cols = ["index start_time stop_time detector target obsid_time unknown type comment "]